
import time
help_str = """
请输入触发异常类型

1 除0
2 超出索引
3 打开不存在的文件
4 未知错误 Exception

"""


def test_main():
    while True:
        print(help_str)
        cmd = input("请输入命令：")
        try:
            if cmd == "1":
                result = 10/0
            elif cmd == "2":
                some_list = [1, 2, 3]
                print(some_list[5])
            elif cmd == "3":
                f = open("not_exist.txt", "r")
            elif cmd == "4":
                raise Exception("未知错误")
            else:
                print("未知命令")

        except ZeroDivisionError as e:
            print("ZeroDivisionError:", e)
        except IndexError as e:
            print("IndexError:", e)
        except FileNotFoundError as e:
            print("FileNotFoundError:", e)
        except Exception as e:
            print("未知异常 Exception:", e)

        finally:
            time.sleep(1)


test_main()
